package smartfleet.mobile.trip;

import java.io.Serializable;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;

import smartfleet.mobile.location.Location;
import smartfleet.mobile.traveller.Traveller;
import smartfleet.mobile.vehicle.Vehicle;

public class Trip implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = -6898326093796911704L;

	private int idTrip;
	private Date infoTimeStap;
	private Vehicle vehicle;
	private Collection<Traveller> travellers;
	private Collection<Location> locations;

	public Trip() {
	}

	public Trip(String id, String infoTimeStap) {
		this.idTrip = Integer.parseInt(id);

		try {
			DateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
			this.infoTimeStap = (java.util.Date) formatter.parse(infoTimeStap);
		} catch (ParseException e) {
			e.printStackTrace();
		}
	}

	/**
	 * @return the idTrip
	 */
	public int getIdTrip() {
		return idTrip;
	}

	/**
	 * @param idTrip
	 *            the idTrip to set
	 */
	public void setIdTrip(int idTrip) {
		this.idTrip = idTrip;
	}

	/**
	 * @return the infoTimeStap
	 */
	public Date getInfoTimeStap() {
		return infoTimeStap;
	}

	/**
	 * @param infoTimeStap
	 *            the infoTimeStap to set
	 */
	public void setInfoTimeStap(Date infoTimeStap) {
		this.infoTimeStap = infoTimeStap;
	}

	/**
	 * @return the vehicle
	 */
	public Vehicle getVehicle() {
		return vehicle;
	}

	/**
	 * @param vehicle
	 *            the vehicle to set
	 */
	public void setVehicle(Vehicle vehicle) {
		this.vehicle = vehicle;
	}

	/**
	 * @return the travellers
	 */
	public Collection<Traveller> getTravellers() {
		return travellers;
	}

	/**
	 * @param travellers
	 *            the travellers to set
	 */
	public void setTravellers(Collection<Traveller> travellers) {
		
		Collection<Location> locs = new ArrayList<Location>();
		for(Traveller traveller : travellers){
			locs.add(traveller.getDestination());

		}
		this.locations = locs;
		
		this.travellers = travellers;
	}

	/**
	 * @return the locations
	 */
	public Collection<Location> getLocations() {
		return locations;
	}

	/**
	 * @param locations
	 *            the locations to set
	 */
	public void setLocations(Collection<Location> locations) {
		this.locations = locations;
	}

}
